$(document).ready(function(){	
	$("#new_email").focus(function(){
		$("#new_email").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	});
	$("#new_email").blur(function(){
		if ($("#new_email").val() == "") {
			$("#new_email").css("background", "url('" + contextPath + "/image/bg_text_new_email.png')");
		}
	});
	

	$("#confirm_email").focus(function(){
		$("#confirm_email").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	});
	$("#confirm_email").blur(function(){
		if ($("#confirm_email").val() == "") {
			$("#confirm_email").css("background", "url('" + contextPath + "/image/bg_text_confirm_email.png')");
		}
	});
	
	$("#customer_password").focus(function(){
		$("#customer_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	});
	$("#customer_password").blur(function(){
		if ($("#customer_password").val() == "") {
			$("#customer_password").css("background", "url('" + contextPath + "/image/bg_text_password.png')");
		}
	});
	
	$("#new_email").focus();
	addFadeEffect();
});

function modifyEmail() {
	var newEmail = $("#new_email").val();
	var confirmEmail = $("#confirm_email").val();
	var password = $("#customer_password").val();
	var params;
	
	var pattern = /^[^\s@]+@[^\s@]+$/;
	if (newEmail == "" || !pattern.test(newEmail)) {
		$("#error_message_modify_email").html("邮箱错误<br/>");
		$("#new_email").css("background", "#fbe2e2");
		return;
	} else {
		$("#error_message_modify_email").html("");
		$("#new_email").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	}
	
	if (confirmEmail != newEmail) {
		$("#error_message_modify_email").html("确认邮箱错误<br/>");
		$("#confirm_email").css("background", "#fbe2e2");
		return;
	} else {
		$("#error_message_modify_email").html("");
		$("#confirm_email").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	}
	
	pattern = /[a-zA-Z0-9]{4,20}/;
	if (password == "" || !pattern.test(password)) {
		$("#error_message_modify_email").html("密码错误<br/>");
		$("#customer_password").css("background", "#fbe2e2");
		return;
	} else {
		$("#error_message_modify_email").html("");
		$("#customer_password").css("background", "url('" + contextPath + "/image/bg_text_blank.png')");
	}
	
	params = {
			request_method:"modify_email",
			new_email:newEmail,
			password:password
	};
	
	$.post("customer_json_servlet", params, function(ret){
		if (ret.code == 0) {
			cancelModifyEmailDlg();
			showMySettingTab();
		} else {
			$("#error_message_modify_email").html(ret.message);
		}
	}, "json");
}